package hut.ai.team.stages;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;

public class Stages extends Stage {
	private Actor prev;
	private Vector2 tmp = new Vector2();
//	public static final int WIDTH = 800;
//	public static final int HEIGHT = 480;
	
	public Stages(float width,float height, boolean b){
		super(width, height, false);
	}
	
	
	
	@Override
	public boolean touchDown(int screenX, int screenY, int pointer, int button) {
		tmp.set(screenX, screenY);
		tmp.set(screenToStageCoordinates(tmp));
		Actor hit = hit(tmp.x, tmp.y, true);
		if(hit!=null){
			System.out.println("hit: "+hit+","+hit.getName());
		}
		if (hit != null && hit.getName() != null) {
			System.out.println("down: " + hit);
			prev = hit;
//			return true;
		}
		return super.touchDown(screenX, screenY, pointer, button);
	}

	@Override
	public boolean touchDragged(int screenX, int screenY, int pointer) {
		if (prev != null) {
			tmp.set(screenX, screenY);
			tmp.set(screenToStageCoordinates(tmp));
			prev.setPosition(tmp.x - prev.getOriginX(),
					tmp.y - prev.getOriginY());
//			return true;
		}
		return super.touchDragged(screenX, screenY, pointer);
	}

	@Override
	public boolean touchUp(int screenX, int screenY, int pointer, int button) {
		if (prev != null) {
			System.out.println("Position: " + prev.getName() + ": "
					+ prev.getX() + "," + prev.getY());
			prev = null;
//			return true;
		}
		return super.touchUp(screenX, screenY, pointer, button);
	}
}
